﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WatiN.Core;
using QAHelper.Common;

namespace Sentrana_QA.WatiNScript.SpoonByteTestScript
{
    public static class RegistrationStepTwo
    {
        private static RestaurantCommon restaurantCommon = new RestaurantCommon();
        static string registrationURL = Properties.Settings.Default.LOGIN_URL;


        public static string TestBRSS_B2_RR1_6(Browser window, DictionaryEntry[] tempTestData)
        {
            #region Local Parameters
            string result = string.Empty;
            int index = registrationURL.LastIndexOf('=');
            string syscoID = registrationURL.Substring(index + 1);
            #endregion

            #region Step 2 Validation

            #region Working @ Step 2
            //if (Window.ContainsText(StepHeaderText.Step2HeaderMessage))
            if (restaurantCommon.LoginAction(window,registrationURL,TestManager.EmailToLogin,TestManager.PasswordToLogin))
            {
                restaurantCommon.CompleteProfileLinkClick(window);

                string welcomeBanner = window.Span(Find.ByClass("dir")).Text;
                welcomeBanner = welcomeBanner.Substring(8);

                if (window.TextField(Find.ById("RestaurantName")).Exists && window.ContainsText(syscoID)
                    && window.TextField(Find.ById("RestaurantName")).Text.Trim() != null
                    && window.TextField(Find.ById("RestaurantName")).Text.Trim().Equals(welcomeBanner))
                {
                    result += Environment.NewLine+"Step 2 registration page loaded successfully." + Environment.NewLine;

                    //Check Open and Close data
                    string dropDownStatus = restaurantCommon.CheckOpenCloseDropDownList(window);
                    if (dropDownStatus != null)
                        result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":One or some " + dropDownStatus + " drop down list(s) are not in proper format." + Environment.NewLine;
                    else
                        result += Environment.NewLine+"All the drop down lists are in proper format." + Environment.NewLine;
                }
                else
                    result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":Step 2 registration page DO NOT loaded successfully." + Environment.NewLine;
            }
            else
                result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":Step 1 registration failed." + Environment.NewLine;
            #endregion

            #endregion

            return result;
        }

        public static string TestBRSS_B2_RR1_7(Browser window, DictionaryEntry[] tempTestData)
        {
            #region Local Parameters
            string result = null;            
            int index = registrationURL.LastIndexOf('=');
            string syscoID = registrationURL.Substring(index + 1);
            #endregion

            #region Step 2 Validation


            #region Login Action
            restaurantCommon.LoginAction(window, registrationURL, TestManager.EmailToLogin, TestManager.PasswordToLogin);
            #endregion

            #region Working @ Step 2
            //if (Window.ContainsText(StepHeaderText.Step2HeaderMessage))
            if (restaurantCommon.CompleteProfileLinkClick(window))
            {
                string welcomeBanner = window.Span(Find.ByClass("dir")).Text;
                welcomeBanner = welcomeBanner.Substring(8);

                if (window.ContainsText(StepHeaderText.Step2HeaderMessage))
                {
                    result += Environment.NewLine+"Step 2 registration page loaded successfully." + Environment.NewLine;

                    #region Test Runs
                    if (tempTestData.Length > 1)
                    {
                        result += Environment.NewLine + Step2EmptyMandatoryFields(window, tempTestData); //EMPTY MANDATORY FIELDS VALIDATION
                        result += Environment.NewLine + Step2InvalidPhoneNumbers(window, tempTestData); //INVALID PRIMARY PHONE NUMBER VALIDATION
                        result += Environment.NewLine + Step2InvalidWebsiteURL(window, tempTestData); //INVALID FORMAT WEBSITE URL VALIDATIN
                        result += Environment.NewLine + Step2InvalidOperatingHour(window, tempTestData); //INVALID OPERATING HOUR VALIDATION
                    }
                    result += Environment.NewLine+Step2ValidDataSet(window, tempTestData); //VALID DATA SET ACTION
                    #endregion
                }
                else
                    result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":Step 2 registration page DO NOT loaded successfully." + Environment.NewLine;
            }
            else
                result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":Step 2 registration failed." + Environment.NewLine;
            #endregion

            #endregion

            return result;

        }

        public static string TestBRSS_B2_RR1_8(Browser window, DictionaryEntry[] tempTestData)
        {
            #region Local Parameters
            string result = null;
            int index = registrationURL.LastIndexOf('=');
            string syscoID = registrationURL.Substring(index + 1);
            Div div;
            #endregion

            #region Step 2 Validation

           
            #region Working @ Step 2
            #region Login Action
            restaurantCommon.LoginAction(window,registrationURL, TestManager.EmailToLogin, TestManager.PasswordToLogin);
            #endregion

            if (restaurantCommon.CompleteProfileLinkClick(window))
            //if (Window.ContainsText("Step 2 of 6: Enter Restaurant Information"))
            {
                string welcomeBanner = window.Span(Find.ByClass("dir")).Text;
                welcomeBanner = welcomeBanner.Substring(8);

                if (window.TextField(Find.ById("RestaurantName")).Exists && window.ContainsText(syscoID)
                    && window.TextField(Find.ById("RestaurantName")).Text.Trim() != null
                    && window.TextField(Find.ById("RestaurantName")).Text.Trim().Equals(welcomeBanner))
                {
                    result += Environment.NewLine+"Step 2 registration page loaded successfully." + Environment.NewLine;

                    window.SelectList(Find.ById("State")).Select("DC");
                    window.Button(Find.ByValue(ButtonsName.RestaurantNeighborhoodButton)).Click();
                    window.WaitForComplete(int.Parse(Properties.Settings.Default.TIMEOUT));

                    div = window.Div(Find.ById("NeighborhoodListDiv"));
                    if (!div.Enabled)
                        result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":Restaurant Neighborhood pop-up did not appear.";
                    else
                    {
                        try
                        {
                            #region Verifying Existance of Data in the Pop-up
                            ArrayList expectedData = CommonHelper.GetDataFromDictionary(tempTestData, 0);
                            string tempMsg = null;

                            foreach (string name in expectedData)
                            {
                                if (!div.Label(Find.ByText(name)).Exists) tempMsg += Environment.NewLine + name;
                            }

                            if (tempMsg != null)
                            {
                                tempMsg = QAHelper.Common.Enum.StatusText.Fail.ToString() + ":Following Neighborhood not found in the pop-up list: " + tempMsg;
                                result += Environment.NewLine+tempMsg;
                                tempMsg = null;
                            }
                            #endregion
                        }
                        catch (Exception e)
                        {
                            result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":Exception Message-> " + e.Message;
                        }
                    }
                }
                else
                    result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":Step 2 registration page DO NOT loaded successfully." + Environment.NewLine;
            }
            else
                result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":Step 2 registration failed." + Environment.NewLine;
            #endregion

            #endregion

            return result;
        }

        public static string TestBRSS_B2_RR1_9(Browser window, DictionaryEntry[] tempTestData)
        {
            #region Local Parameters
            string result = null;
            int index = registrationURL.LastIndexOf('=');
            string syscoID = registrationURL.Substring(index + 1);
            ArrayList checkedValues = new ArrayList();
            bool flag = flag = false;
            Button neighborhood;
            string geographicId = null;
            #endregion

            #region Step 2 Validation

            #region Working @ Step 2
            #region Login Action
            restaurantCommon.LoginAction(window,registrationURL, TestManager.EmailToLogin, TestManager.PasswordToLogin);
            #endregion

            if (restaurantCommon.CompleteProfileLinkClick(window))
            //if (Window.ContainsText(StepHeaderText.Step2HeaderMessage))
            {
                string welcomeBanner = window.Span(Find.ByClass("dir")).Text;
                welcomeBanner = welcomeBanner.Substring(8);
                Div div;

                if (window.TextField(Find.ById("RestaurantName")).Exists && window.ContainsText(syscoID)
                    && window.TextField(Find.ById("RestaurantName")).Text.Trim() != null
                    && window.TextField(Find.ById("RestaurantName")).Text.Trim().Equals(welcomeBanner))
                {
                    result += Environment.NewLine+"Step 2 registration page loaded successfully." + Environment.NewLine;

                    try
                    {
                        #region Opening Neighborhood pop-up
                        window.SelectList(Find.ById("State")).Select("DC");
                        neighborhood = window.Button(Find.ByValue(ButtonsName.RestaurantNeighborhoodButton));
                        neighborhood.Click();
                        window.WaitForComplete(int.Parse(Properties.Settings.Default.TIMEOUT));
                        #endregion

                        div = window.Div(Find.ById("NeighborhoodListDiv"));
                        if (!div.Exists)
                            result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":Restaurant Neighborhood pop-up did not appear.";
                        else
                        {
                            int count = div.CheckBoxes.Count;

                            #region Generating Geographic Area ID
                            for (int i = 0; i < 5; i++)
                            {
                                geographicId = "geographicArea_chk_" + new Random().Next(1, count - 1);
                                if (checkedValues.Contains(geographicId))
                                    i--;
                                else
                                    checkedValues.Add(geographicId);
                            }
                            #endregion

                            #region Test Runs
                            result += Environment.NewLine+ClearFormLinkAction(window, count, div, checkedValues);
                            result += Environment.NewLine+CancelButtonAction(count, neighborhood, div, checkedValues, window);
                            result += Environment.NewLine+DoneButtonAction(count, neighborhood, div, checkedValues, window);
                            #endregion
                        }
                    }
                    catch (Exception e) { }
                }
                else
                    result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":Step 2 registration page DO NOT loaded successfully." + Environment.NewLine;
            }
            else
                result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":Step 2 registration failed." + Environment.NewLine;
            #endregion

            #endregion

            return result;

        }

        public static string TestBRSS_B2_RR1_11(Browser window, DictionaryEntry[] tempTestData)
        {
            #region Local Parameters

            string result = null;
            int index = registrationURL.LastIndexOf('=');
            string syscoID = registrationURL.Substring(index + 1);
            ArrayList checkedValues = new ArrayList();
            bool flag = flag = false;
            #endregion

            #region Step 2 Validation

            #region Working @ Step 2

            #region Login Action
            restaurantCommon.LoginAction(window, registrationURL, TestManager.EmailToLogin, TestManager.PasswordToLogin);
            #endregion

            if (restaurantCommon.CompleteProfileLinkClick(window))
            //if (Window.ContainsText(StepHeaderText.Step2HeaderMessage))
            {
                string welcomeBanner = window.Span(Find.ByClass("dir")).Text;
                welcomeBanner = welcomeBanner.Substring(8);

                if (window.TextField(Find.ById("RestaurantName")).Exists && window.ContainsText(syscoID)
                    && window.TextField(Find.ById("RestaurantName")).Text.Trim() != null
                    && window.TextField(Find.ById("RestaurantName")).Text.Trim().Equals(welcomeBanner))
                {
                    result += Environment.NewLine+"Step 2 registration page loaded successfully." + Environment.NewLine;

                    #region Other than Monday
                    //Same time every day
                    window.SelectList(Find.ById("OperatingHourList[1]_StartDateTime")).Select("08:30 AM");
                    window.SelectList(Find.ById("OperatingHourList[1]_EndDateTime")).Select("02:30 PM");
                    window.Link(Find.ByText("Same time every day")).Click();

                    if (window.SelectList(Find.ById("OperatingHourList[1]_StartDateTime")).SelectedItem.ToString().Trim().Equals("08:30 AM")
                        && window.SelectList(Find.ById("OperatingHourList[1]_EndDateTime")).SelectedItem.ToString().Trim().Equals("02:30 PM"))
                    {
                        result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":'Same time every day' link click event does not work.";
                    }
                    else
                        result += Environment.NewLine+"'Same time every day' link click event works properly.";

                    //Same time Mon-Fri
                    window.SelectList(Find.ById("OperatingHourList[1]_StartDateTime")).Select("08:30 AM");
                    window.SelectList(Find.ById("OperatingHourList[1]_EndDateTime")).Select("02:30 PM");
                    window.Link(Find.ByText("Same time Mon - Fri")).Click();

                    if (window.SelectList(Find.ById("OperatingHourList[1]_StartDateTime")).SelectedItem.ToString().Trim().Equals("08:30 AM")
                        && window.SelectList(Find.ById("OperatingHourList[1]_EndDateTime")).SelectedItem.ToString().Trim().Equals("02:30 PM"))
                    {
                        result += Environment.NewLine+"'Same time Mon-Fri' link click event does not work.";
                    }
                    else
                        result += Environment.NewLine+"'Same time Mon-Fri' link click event works properly.";
                    #endregion

                    #region Monday
                    //Same time every day
                    window.SelectList(Find.ById("OperatingHourList[0]_StartDateTime")).Select("08:30 AM");
                    window.SelectList(Find.ById("OperatingHourList[0]_EndDateTime")).Select("02:30 PM");
                    window.Link(Find.ByText("Same time every day ")).Click();

                    if (!window.SelectList(Find.ById("OperatingHourList[1]_StartDateTime")).SelectedItem.ToString().Trim().Equals("08:30 AM")
                        && !window.SelectList(Find.ById("OperatingHourList[1]_EndDateTime")).SelectedItem.ToString().Trim().Equals("02:30 PM"))
                    {
                        result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":'Same time every day' link click event does not work.";
                    }
                    else
                        result += Environment.NewLine+"'Same time every day' link click event works properly.";

                    //Same time Mon-Fri
                    window.SelectList(Find.ById("OperatingHourList[0]_StartDateTime")).Select("10:30 AM");
                    window.SelectList(Find.ById("OperatingHourList[0]_EndDateTime")).Select("04:30 PM");
                    window.Link(Find.ByText("Same time Mon - Fri")).Click();

                    if (!window.SelectList(Find.ById("OperatingHourList[1]_StartDateTime")).SelectedItem.ToString().Trim().Equals("10:30 AM")
                        && !window.SelectList(Find.ById("OperatingHourList[1]_EndDateTime")).SelectedItem.ToString().Trim().Equals("04:30 PM")
                        && window.SelectList(Find.ById("OperatingHourList[6]_StartDateTime")).SelectedItem.ToString().Trim().Equals("10:30 AM")
                        && window.SelectList(Find.ById("OperatingHourList[6]_EndDateTime")).SelectedItem.ToString().Trim().Equals("04:30 PM"))
                    {
                        result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":'Same time Mon-Fri' link click event does not work.";
                    }
                    else
                        result += Environment.NewLine+"'Same time Mon-Fri' link click event works properly.";
                    #endregion

                }
                else
                    result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":Step 2 registration page DO NOT loaded successfully." + Environment.NewLine;
            }
            else
                result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":Step 2 registration failed." + Environment.NewLine;
            #endregion

            #endregion

            return result;
        }

        public static string TestBRSS_B2_RR1_13(Browser window, DictionaryEntry[] tempTestData)
        {
            #region Local Parameters
            string result = null;
            int index = registrationURL.LastIndexOf('=');
            string syscoID = registrationURL.Substring(index + 1);
            #endregion

            #region Step 2 Validation

            #region Working @ Step 2

            #region Login Action
            restaurantCommon.LoginAction(window, registrationURL, TestManager.EmailToLogin, TestManager.PasswordToLogin);
            #endregion

            if (restaurantCommon.CompleteProfileLinkClick(window))
            //if (Window.ContainsText(StepHeaderText.Step2HeaderMessage))
            {
                string welcomeBanner = window.Span(Find.ByClass("dir")).Text;
                welcomeBanner = welcomeBanner.Substring(8);

                if (window.TextField(Find.ById("RestaurantName")).Exists && window.ContainsText(syscoID)
                    && window.TextField(Find.ById("RestaurantName")).Text.Trim() != null
                    && window.TextField(Find.ById("RestaurantName")).Text.Trim().Equals(welcomeBanner))
                {
                    result += Environment.NewLine+"Step 2 registration page loaded successfully." + Environment.NewLine;

                    #region Test Runs
                    result += Environment.NewLine+Step2CancelButtonAction(window,tempTestData); //CANCEL BUTTON ACTION                    
                    result += Environment.NewLine+Step2ValidDataSet(window,tempTestData); //DONE BUTTON ACTION
                    #endregion
                }
                else
                    result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":Step 2 registration page DO NOT loaded successfully." + Environment.NewLine;
            }
            else
                result += Environment.NewLine+QAHelper.Common.Enum.StatusText.Fail.ToString() + ":Step 2 registration failed." + Environment.NewLine;
            #endregion

            #endregion

            return result;
        }

        #region Private methods

        #region Step 2 Empty Mandatory Fields Checking

        private static string Step2EmptyMandatoryFields(Browser window, DictionaryEntry[] dataSet)
        {
            #region Local Params
            string result = string.Empty;
            int noOfFields = 0;
            ArrayList dataArray;
            DictionaryEntry thisStepDictionary = dataSet[0];
            string dataSetHeader = Properties.Settings.Default.DATA_SET_DELIM_START + thisStepDictionary.Key.ToString() + Properties.Settings.Default.DATA_SET_DELIM_END;
            #endregion

            #region Insert Action

            dataArray = CommonHelper.GetDataFromDictionary(dataSet, 0);
            WatiNInputHelper.SetPageInput(window, dataArray, out noOfFields);

            window.Button(Find.ByValue(ButtonsName.SaveButton)).Click();
            window.WaitForComplete();
            #endregion

            #region Error list

            result += dataSetHeader+Environment.NewLine;
            
            if (!window.ContainsText("Street address 1 cannot be empty."))
                result += Environment.NewLine+"Street address error message not shown for empty value.";
            if (!window.ContainsText("Restaurant description cannot be empty."))
                result += Environment.NewLine+"Restaurant description error message not shown for empty value.";
            if (!window.ContainsText("City cannot be empty."))
                result += Environment.NewLine+"City error message not shown for empty value.";
            if (!window.ContainsText("Please select state."))
                result += Environment.NewLine+"State error message not shown for empty value.";
            if (!window.ContainsText("Zipcode cannot be empty."))
                result += Environment.NewLine+"Zipcode error message not shown for empty value.";
            if (!window.ContainsText("Primary phone number cannot be empty."))
                result += Environment.NewLine+"Primary phone number error message not shown for empty value.";
            if (!window.ContainsText("Redemption line phone number cannot be empty."))
                result += Environment.NewLine+"Redemption line phone number error message not shown for empty value.";
            if (!window.ContainsText("Website URL cannot be empty."))
                result += Environment.NewLine+"Website URL error message not shown for empty value.";
            if (!window.ContainsText("Please select operating hours for each day."))
                result += Environment.NewLine+"Operating hour error message not shown for empty value.";
            #endregion

            return result;
        }

        #endregion

        #region Step 2 Invalid Phone Number Validation

        private static string Step2InvalidPhoneNumbers(Browser window, DictionaryEntry[] dataSet)
        {
            #region Local Params
            string result = string.Empty;
            int noOfFields = 0;
            ArrayList dataArray;
            DictionaryEntry thisStepDictionary = dataSet[1];
            string dataSetHeader = Properties.Settings.Default.DATA_SET_DELIM_START + thisStepDictionary.Key.ToString() + Properties.Settings.Default.DATA_SET_DELIM_END;
            #endregion

            #region Insert Action

            dataArray = CommonHelper.GetDataFromDictionary(dataSet, 1);
            WatiNInputHelper.SetPageInput(window, dataArray, out noOfFields);

            window.Button(Find.ByValue(ButtonsName.SaveButton)).Click();
            window.WaitForComplete();
            #endregion

            #region Error list

            result += dataSetHeader + Environment.NewLine;

            if (!window.ContainsText("Primary phone number is not in correct format."))
                result += Environment.NewLine+"Primary phone number invalid format error message not shown.";
            if (!window.ContainsText("Redemption line phone number is not in correct format."))
                result += Environment.NewLine+"Redemption line phone number invalid format error message not shown.";
            if (!window.ContainsText("Fax number is not in correct format."))
                result += Environment.NewLine+"Fax number invalid format error message not shown.";
            #endregion

            return result;
        }
        #endregion

        #region Step 2 Invalid Website URL Validation

        private static string Step2InvalidWebsiteURL(Browser window, DictionaryEntry[] dataSet)
        {
            #region Local Params
            string result = string.Empty;
            int noOfFields = 0;
            ArrayList dataArray;
            DictionaryEntry thisStepDictionary = dataSet[2];
            string dataSetHeader = Properties.Settings.Default.DATA_SET_DELIM_START + thisStepDictionary.Key.ToString() + Properties.Settings.Default.DATA_SET_DELIM_END;
            #endregion

            #region Insert Action

            dataArray = CommonHelper.GetDataFromDictionary(dataSet, 2);
            WatiNInputHelper.SetPageInput(window, dataArray, out noOfFields);

            window.Button(Find.ByValue(ButtonsName.SaveButton)).Click();
            window.WaitForComplete();
            #endregion

            #region Error list

            result += dataSetHeader + Environment.NewLine;

            if (!window.ContainsText("Website URL is not valid."))
                result += Environment.NewLine+"Website URL invalid format error message not shown.";
            #endregion

            return result;
        }
        #endregion

        #region Step 2 Invalid Operating Hour Validation

        private static string Step2InvalidOperatingHour(Browser window, DictionaryEntry[] dataSet)
        {
            #region Local Params
            string result = string.Empty;
            int noOfFields = 0;
            ArrayList dataArray;
            Link sameTime = window.Link(Find.ByValue("Same time every day "));
            DictionaryEntry thisStepDictionary = dataSet[3];
            string dataSetHeader = Properties.Settings.Default.DATA_SET_DELIM_START + thisStepDictionary.Key.ToString() + Properties.Settings.Default.DATA_SET_DELIM_END;
            #endregion

            #region Open > Close checking for Monday as Base

            result += dataSetHeader + Environment.NewLine;

            #region Insert Action

            dataArray = CommonHelper.GetDataFromDictionary(dataSet, 3);
            WatiNInputHelper.SetPageInput(window, dataArray, out noOfFields);
            sameTime.Click();

            window.Button(Find.ByValue(ButtonsName.SaveButton)).Click();
            window.WaitForComplete();
            #endregion

            #region Error list          

            if (!window.ContainsText("Opening time cannot be greater than or same as closing time."))
                result += Environment.NewLine+"'Open > Close' error message not shown. (Moday as base)";

            #endregion
            #endregion

            #region Open > Close checking for Monday as Base

            #region Insert Action

            dataArray = CommonHelper.GetDataFromDictionary(dataSet, 3);
            WatiNInputHelper.SetPageInput(window, dataArray, out noOfFields);
            window.SelectList("OperatingHourList[0]_StartDateTime").Select("07:00 AM");
            window.SelectList("OperatingHourList[0]_EndDateTime").Select("07:00 PM");
            sameTime.Click();
            //Making a random day's open > close operating hour (it excludes Monday)
            int index = new Random().Next(1, 6);
            window.SelectList("OperatingHourList[" + index + "]_StartDateTime").Select("07:00 PM");
            window.SelectList("OperatingHourList[" + index + "]_EndDateTime").Select("07:00 AM");

            window.Button(Find.ByValue(ButtonsName.SaveButton)).Click();
            window.WaitForComplete();
            #endregion

            #region Error list

            if (!window.ContainsText("Opening time cannot be greater than or same as closing time."))
                result += Environment.NewLine+"'Open > Close' error message not shown. (for a Random Day)";
            #endregion
            #endregion

            return result;
        }
        #endregion

        #region Step 2 Valid Data Set

        private static string Step2ValidDataSet(Browser window, DictionaryEntry[] dataSet)
        {
            #region Local Params
            string result = string.Empty;
            int noOfFields = 0;
            ArrayList dataArray;
            Button sameTime = window.Button(Find.ByValue("Same time every day"));
            DictionaryEntry thisStepDictionary = new DictionaryEntry();
            int thisIndex = 0;

            if (dataSet.Length > 1)
                thisIndex = 4;

            thisStepDictionary = dataSet[thisIndex];

            string dataSetHeader = Properties.Settings.Default.DATA_SET_DELIM_START + thisStepDictionary.Key.ToString() + Properties.Settings.Default.DATA_SET_DELIM_END;
            result += dataSetHeader + Environment.NewLine;
            #endregion

            #region Insert Action

            dataArray = CommonHelper.GetDataFromDictionary(dataSet, thisIndex);
            WatiNInputHelper.SetPageInput(window, dataArray, out noOfFields);
            sameTime.Click();

            window.Button(Find.ByValue(ButtonsName.SaveButton)).Click();
            window.WaitForComplete();
            #endregion

            #region Success verification
            if (window.ContainsText(StepHeaderText.Step3HeaderMessage))
                result += Environment.NewLine+"Step 2 registration successful.";
            else
                result += Environment.NewLine+"Step 2 registration failed.";
            #endregion

            return result;
        }
        #endregion

        #region BRSS_B2_RR1_9 TEST RUNS

        #region Clear Form Link Action

        private static string ClearFormLinkAction(Browser window,int count, Div div, ArrayList checkedValues)
        {
            #region Local Params
            string result = null;
            bool flag = false;
            #endregion

            //Checkboxes Checked
            for (int i = 0; i < 5; i++)
            {
                div.CheckBox(Find.ById(checkedValues[i].ToString())).Checked = true;
            }

            //Clear form link clicked
            //div.Link(Find.ByLabelText("             Clear Form")).Click();
            div.Label(Find.ByText("Clear Form")).Click();

            //Verify whether checkboxes are unchecked or not
            foreach (string checkBox in checkedValues)
            {
                if (window.CheckBox(Find.ById(checkBox)).Checked)
                {
                    result += Environment.NewLine+"Restaurant neighborhood check box(es) not cleared properly";
                    flag = true;
                    break;
                }
            }

            if (!flag) result += Environment.NewLine+"All restaurant negihborhood check boxes are cleared successfully.";

            return result;
        }
        #endregion

        #region Cancel Button Action

        private static string CancelButtonAction(int count, Button neighborhood, Div div, ArrayList checkedValues, Browser window)
        {
            #region Local Params
            string result = null;
            bool flag = false;
            #endregion

            try
            {
                //Checkboxes Checked
                for (int i = 0; i < 5; i++)
                {
                    div.CheckBox(Find.ById(checkedValues[i].ToString())).Checked = true;
                }

                //Cancel clicked
                window.Button(Find.ByName("CancelButton")).Click();

                //Reopen pop-up
                neighborhood.Click();

                //Verify whether selected checkboxes are canceled or not
                foreach (string checkBox in checkedValues)
                {
                    if (div.CheckBox(Find.ById(checkBox)).Checked)
                    {
                        result += Environment.NewLine+"Restaurant neighborhood check box(es) not cleared properly on CANCEL";
                        flag = true;
                        break;
                    }
                }

                if (!flag) result += Environment.NewLine+"All restaurant negihborhood check boxes are cleared successfully on CANCEL.";
            }
            catch (Exception e) { }

            return result;
        }
        #endregion

        #region Done Button Action

        private static string DoneButtonAction(int count, Button neighborhood, Div div, ArrayList checkedValues, Browser window)
        {
            #region Local Params
            string result = string.Empty;
            bool flag = false;
            #endregion

            //Checkboxes Checked
            for (int i = 0; i < 5; i++)
            {
                div.CheckBox(Find.ById(checkedValues[i].ToString())).Checked = true;
            }

            //Cancel clicked
            window.Button(Find.ByName("DoneButton")).Click();

            //Reopen pop-up
            neighborhood.Click();

            //Verify whether selected checkboxes are canceled or not
            foreach (string checkBox in checkedValues)
            {
                if (!window.CheckBox(Find.ById(checkBox)).Checked)
                {
                    result += Environment.NewLine+"Restaurant neighborhood check box(es) not saved properly";
                    flag = true;
                    break;
                }
            }

            if (!flag) result += Environment.NewLine+"All restaurant negihborhood check boxes are saved successfully.";

            return result;
        }
        #endregion

        #endregion

        #region BRSS_B2_RR1_13 TEST RUN

        #region Step 2 Cancel Button Action
        private static string Step2CancelButtonAction(Browser window, DictionaryEntry[] dataSet)
        {
            #region Local Params
            string result = null;
            int noOfFields = 0;
            ArrayList dataArray;
            Button cancelButton = window.Button(Find.ByValue(ButtonsName.CancelButton) & Find.ByName("Submit")); ;
            Link sameTime = window.Link(Find.ByText("Same time every day "));
            DictionaryEntry thisStepDictionary = dataSet[4];
            string dataSetHeader = Properties.Settings.Default.DATA_SET_DELIM_START + thisStepDictionary.Key.ToString() + Properties.Settings.Default.DATA_SET_DELIM_END;
            result += dataSetHeader + Environment.NewLine;
            #endregion

            #region Insert Action

            dataArray = CommonHelper.GetDataFromDictionary(dataSet, 4); //Accessing Success data set for test case #7
            WatiNInputHelper.SetPageInput(window, dataArray, out noOfFields);
            sameTime.Click();

            cancelButton.Click();
            window.WaitForComplete();
            #endregion

            #region Error list
            if (window.ContainsText(StepHeaderText.Step1HeaderMessage))
            {
                result += Environment.NewLine+"Cancel button worked successfully.";

                window.Button(Find.ByValue(ButtonsName.SaveButton)).Click();
                window.WaitForComplete();

                if (window.ContainsText(StepHeaderText.Step2HeaderMessage))
                {
                    string temp = window.TextField(Find.ById("StreetAddress1")).Text;

                    if (temp != null)
                        result += Environment.NewLine+"Cancel button does not cancel the Step 2 save action.";
                    else
                        result += Environment.NewLine+"Cancel button canceled the Step 2 save action successfully.";
                }
                else
                    result += Environment.NewLine+"Unable to navigate to Step 2";
            }
            else
                result += Environment.NewLine+"Step 2 completion failed.";
            #endregion

            return result;
        }
        #endregion

        #endregion

        #endregion
    }
}
